<!DOCTYPE html>
<#assign ctx = request.contextPath />
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1 ,minimum-scale=1.0 ,maximum-scale=1.0" user-scalable=no>
    <title>历史订单</title>
    <link href="${ctx}/assets/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="${ctx}/assets/css/weixing.css" />
   <link rel="stylesheet" href="${ctx}/assets/css/hook.css" />
   <link rel="stylesheet" href="${ctx}/assets/css/sco.message.css" />
  </head>
  <body>
  <div class="hook" id="hook">
</div>
  	<ul id="thelist">
  
	</ul>
	<div style="text-align:center" id="loadmore">
		点击加载更多
	</div>
<script src="${ctx}/assets/js/jquery-1.11.0.min.js"></script>
 <script src="${ctx}/assets/js/sco.message.js"></script>
<script src="${ctx}/assets/js/bootstrap.min.js"></script>
<script src="${ctx}/assets/js/mousewheel.js"></script>
<script src="${ctx}/assets/js/hook.js"></script>
<script type="text/javascript">
var myScroll,
	pullDownEl, pullDownOffset,
	pullUpEl, pullUpOffset,
	generatedCount = 0;

function load (page) {
	$.ajax({
             type: "GET",
             url: "${ctx}/wx/v1/historyOrder3",
             data: {
             'phone':'${phone}',
             'pager.offset':(page-1)*10,
             'limit':10
             },	
             dataType: "json",
             success: function(data){ 
             if(data.length==0 && $("li > div").val()==null){
             $("#loadmore").html("暂无历史订单");
             }
              if(null!=data &&data.length>0 ){
             	 var content="";
             	 var  orderNumber , orderTotalCost, orderTargetAddress,orderCreatedTime,orderStatus,orderId;
				  $.each(data, function (i,order) {  
			          	 orderNumber=order.orderNumber;
			          	 orderId=order.orderId;
			          	 orderTotalCost=order.orderTotalCost;
			          	 orderTargetAddress=order.orderTargetAddress==null?"":order.orderTargetAddress;
			          	 orderCreatedTimeStr=order.orderCreatedTimeStr;
			          	 if(order.hasbeenRate){
			          	 hasbeenRate='<p style="text-align: right; margin-bottom: 0px; color: #0edb1c;">已评价</p>';
			          	 }else{
			          	 hasbeenRate='<p  style="text-align: right; margin-bottom: 0px; color: #FF0000;">未评价</p>';
			          	 }
			          	 orderStatus=order.orderStatus;
			             content+='<li  class="list-group" orderId="'+order.orderId+'" phone="'+${phone}+'" hasDriver="'+order.hasDriver+'" hasbeenRate="'+order.hasbeenRate+'">';
			             content+='<div class="list-group-item active">';
			             content+='<p style="text-align:left; float: left; margin-bottom: 0px;">订单号:';
			             content+=orderNumber;
			             content+='</p>';
			             content+='<p style="text-align: right; margin-bottom: 0px;">订单金额:';
			             content+=orderTotalCost;
			             content+='元</p>';
			             content+='</div>';
			             content+='<div class="list-group-item">';
			             content+='<p style="text-align:left; float: left; margin-bottom: 0px;">目的地:</p>';
			             content+='<p style="text-align: right; margin-bottom: 0px;">';
			             content+=orderTargetAddress;
			             content+='&nbsp;</p>';
			             content+='</div>';
			             content+='<div class="list-group-item">';
			             content+='<p style="text-align:left; float: left; margin-bottom: 0px;"> 下单时间:</p>';
			             content+='<p style="text-align: right; margin-bottom: 0px;">';
			             content+=orderCreatedTimeStr;
			             content+='&nbsp;</p></div>';
			             content+='<div class="list-group-item">';
			             content+='<p style="text-align:left; float: left; margin-bottom: 0px;">当前状态:</p>';
			             content+='<p style="text-align: right; margin-bottom: 0px;">';
			             content+=orderStatus;
			             content+='&nbsp;</p></div>';
			             content+='<div class="list-group-item">';
			             content+='<p style="text-align:left; float: left; margin-bottom: 0px;">评价:</p>';
			             content+=hasbeenRate;
			             content+='</div></li>';
			       }); 
			        if(page==1){
			       	 $("#thelist").empty();
			       }
			       $("#thelist").append(content);
			      
			    }else if( $("li > div").val()!=null){
			    	$("#loadmore").html("没有更多历史订单了");
			    }
	         }
     });	
}
var page = 1;
var ctx='${ctx}';
$(document).ready(function(){
	load(1);
	$('#hook').hook({
		reloadPage:false,
		reloadEl:function(){
			load(1);
			page=1;
			$("#loadmore").html("点击加载更多");
		}
	});
	
	
	
	$("#loadmore").click(function(){
		page++;
		if($("#loadmore").html()=="没有更多历史订单了" || $("#loadmore").html()=="暂无历史订单" ){
		}else{
			load(page);
		}
	});
});
$(document).on('click','.list-group',function(){
			var hasbeenRate=$(this).attr("hasbeenRate");
			var hasDriver=$(this).attr("hasDriver");
		  if(hasbeenRate=="false" && hasDriver==1){
			var orderId=$(this).attr("orderId");
			var phone=$(this).attr("phone");
     	  	window.location.href =ctx+"/wx/v1/evaluate?orderId="+orderId+"&phone="+phone;
		  }else{
		  	$.scojs_message("服务人员已被移除,无法评价.", $.scojs_message.TYPE_ERROR);	
		  }
		  
});
</script>
</body>
</html>